Skip to contentSkip to conversation

amdgpu: fix overflow for timeout calculation

PATCH In review Alex Deucher 3 participants 5 messages Nov 21, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 amdgpu: fix overflow for timeout calculation

From: Jammy Zhou <[email protected]>

Set the timeout to AMDGPU_TIMEOUT_INFINITE when overflow happens

---
 amdgpu/amdgpu_cs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
amdgpu/amdgpu_cs.c +6 -2
index 4da9821..aa594c4 100644
@@ -289,12 +289,16 @@ drm_private uint64_t amdgpu_cs_calculate_timeout(uint64_t timeout)
 
 	if (timeout != AMDGPU_TIMEOUT_INFINITE) {
 		struct timespec current;
+		uint64_t current_ns;
 		r = clock_gettime(CLOCK_MONOTONIC, &current);
 		if (r)
 			return r;
 
-		timeout += ((uint64_t)current.tv_sec) * 1000000000ull;
-		timeout += current.tv_nsec;
+		current_ns = ((uint64_t)current.tv_sec) * 1000000000ull;
+		current_ns += current.tv_nsec;
+		timeout += current_ns;
+		if (timeout < current_ns)
+			timeout = AMDGPU_TIMEOUT_INFINITE;
 	}
 	return timeout;
 }
Signature · 6 lines
1.8.3.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/2 amdgpu: Make amdgpu_cs_calculate_timeout() return something sensible on error

From: Tom St Denis <[email protected]>

---
 amdgpu/amdgpu_cs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
amdgpu/amdgpu_cs.c +4 -2
index aa594c4..6747158 100644
@@ -291,8 +291,10 @@ drm_private uint64_t amdgpu_cs_calculate_timeout(uint64_t timeout)
 		struct timespec current;
 		uint64_t current_ns;
 		r = clock_gettime(CLOCK_MONOTONIC, &current);
-		if (r)
-			return r;
+		if (r) {
+			fprintf(stderr, "clock_gettime() returned error (%d)!", errno);
+			return AMDGPU_TIMEOUT_INFINITE;
+		}
 
 		current_ns = ((uint64_t)current.tv_sec) * 1000000000ull;
 		current_ns += current.tv_nsec;
Signature · 6 lines
1.8.3.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
In reply to Alex Deucher

I guess the patches should be for drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c instead?

Regards
//Ernst

2015-11-21 1:24 GMT+01:00 Alex Deucher <[email protected]>:

Quoted 37 lines

From: Jammy Zhou <[email protected]>

Set the timeout to AMDGPU_TIMEOUT_INFINITE when overflow happens

---
 amdgpu/amdgpu_cs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
amdgpu/amdgpu_cs.c +6 -2
index 4da9821..aa594c4 100644
@@ -289,12 +289,16 @@ drm_private uint64_t
 amdgpu_cs_calculate_timeout(uint64_t timeout)
 
        if (timeout != AMDGPU_TIMEOUT_INFINITE) {
                struct timespec current;
+               uint64_t current_ns;
                r = clock_gettime(CLOCK_MONOTONIC, &current);
                if (r)
                        return r;
 
-               timeout += ((uint64_t)current.tv_sec) * 1000000000ull;
-               timeout += current.tv_nsec;
+               current_ns = ((uint64_t)current.tv_sec) * 1000000000ull;
+               current_ns += current.tv_nsec;
+               timeout += current_ns;
+               if (timeout < current_ns)
+                       timeout = AMDGPU_TIMEOUT_INFINITE;
        }
        return timeout;

}
--
1.8.3.1

Quoted 5 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 1 line · Ernst Sjöstrand

I guess the patches should be for drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c instead?

No, why do you think so? This is a libdrm patch, not a kernel patch.

Regards,
Christian.

Quoted 55 lines

Regards
//Ernst

2015-11-21 1:24 GMT+01:00 Alex Deucher <[email protected] <mailto:[email protected]>>:

    From: Jammy Zhou <[email protected] <mailto:[email protected]>>

    Set the timeout to AMDGPU_TIMEOUT_INFINITE when overflow happens

    Signed-off-by: Jammy Zhou <[email protected]
    <mailto:[email protected]>>
    Reviewed-by: Christian König <[email protected]
    <mailto:[email protected]>>
    ---
     amdgpu/amdgpu_cs.c | 8 ++++++--
     1 file changed, 6 insertions(+), 2 deletions(-)

    diff --git a/amdgpu/amdgpu_cs.c b/amdgpu/amdgpu_cs.c
    index 4da9821..aa594c4 100644
    --- a/amdgpu/amdgpu_cs.c
    +++ b/amdgpu/amdgpu_cs.c
    @@ -289,12 +289,16 @@ drm_private uint64_t
    amdgpu_cs_calculate_timeout(uint64_t timeout)

            if (timeout != AMDGPU_TIMEOUT_INFINITE) {
                    struct timespec current;
    +               uint64_t current_ns;
                    r = clock_gettime(CLOCK_MONOTONIC, &current);
                    if (r)
                            return r;

    -               timeout += ((uint64_t)current.tv_sec) * 1000000000ull;
    -               timeout += current.tv_nsec;
    +               current_ns = ((uint64_t)current.tv_sec) *
    1000000000ull;
    +               current_ns += current.tv_nsec;
    +               timeout += current_ns;
    +               if (timeout < current_ns)
    +                       timeout = AMDGPU_TIMEOUT_INFINITE;
            }
            return timeout;
     }
    --
    1.8.3.1

    _______________________________________________
    dri-devel mailing list
    [email protected]
    <mailto:[email protected]>
    http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Doh, I didn't get that! Sorry.

Regards
//Ernst

2015-11-21 12:07 GMT+01:00 Christian König <[email protected]>:

Quoted 55 lines · Ernst Sjöstrand

I guess the patches should be for drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c instead?

No, why do you think so? This is a libdrm patch, not a kernel patch.

Regards,
Christian.

Regards
//Ernst

2015-11-21 1:24 GMT+01:00 Alex Deucher <[email protected]>:

Quoted 37 lines

From: Jammy Zhou <[email protected]>

Set the timeout to AMDGPU_TIMEOUT_INFINITE when overflow happens

---
 amdgpu/amdgpu_cs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
amdgpu/amdgpu_cs.c +6 -2
index 4da9821..aa594c4 100644
@@ -289,12 +289,16 @@ drm_private uint64_t
 amdgpu_cs_calculate_timeout(uint64_t timeout)
 
        if (timeout != AMDGPU_TIMEOUT_INFINITE) {
                struct timespec current;
+               uint64_t current_ns;
                r = clock_gettime(CLOCK_MONOTONIC, &current);
                if (r)
                        return r;
 
-               timeout += ((uint64_t)current.tv_sec) * 1000000000ull;
-               timeout += current.tv_nsec;
+               current_ns = ((uint64_t)current.tv_sec) * 1000000000ull;
+               current_ns += current.tv_nsec;
+               timeout += current_ns;
+               if (timeout < current_ns)
+                       timeout = AMDGPU_TIMEOUT_INFINITE;
        }
        return timeout;

}
--
1.8.3.1

Quoted 13 lines
Quoted 5 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing [email protected]://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel